package com.jiazhong.front.controller;

import com.jiazhong.commons.Util.JsonResult;
import com.jiazhong.commons.Util.ResultTool;
import com.jiazhong.front.service.ShoppingCartService;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.apache.coyote.http11.HttpOutputBuffer;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/shopping")
public class ShoppingCartController {
    @Resource
    private ShoppingCartService service;
    @PostMapping("/add/{bookId}")
    public JsonResult add(HttpServletRequest request, @PathVariable("bookId") String bookId) {
        return service.add(request.getHeader("token"), bookId);
    }

    @GetMapping("/find")
    public JsonResult find(HttpServletRequest request) {
        return service.find(request.getHeader("token"));
    }

    @PutMapping("/change_number/{bookId}/{number}")
    public JsonResult changeNumber(HttpServletRequest request, @PathVariable("bookId") String bookId, @PathVariable("number") int number) {
        return service.changeNumber(request.getHeader("token"), bookId, number);
    }

    @PutMapping("/change_number2/{bookId}/{number}")
    public JsonResult changeNumber2(HttpServletRequest request, @PathVariable("bookId") String bookId, @PathVariable("number") int number) {
        return service.changeNumber2(request.getHeader("token"), bookId, number);
    }

    @DeleteMapping("/remove/{bookId}")
    public JsonResult remove(HttpServletRequest request, @PathVariable("bookId") String bookId) {
        return service.remove(request.getHeader("token"), bookId);
    }
    @DeleteMapping("/remove_batch")
    public JsonResult removeBatch(HttpServletRequest request,@RequestParam("bookId") String bookId) {
        System.out.println(bookId);
        return service.removeBatch(request.getHeader("token"), bookId.split("A"));
    }
}
